/*
 * Copyright (c) 2020, 2025, keyila All rights reserved.
 *
 */
package com.clp.init;

import com.clp.util.SpringContextUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author clp
 * @version 1.0
 */
@Component
public class InitCache implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        ApplicationContext applicationContext = SpringContextUtil.getApplicationContext();
        Map<String, AbstractCache> beanMap = applicationContext.getBeansOfType(AbstractCache.class);
        if (beanMap.isEmpty()){
            return;
        }
        for (Map.Entry<String,AbstractCache> entry:beanMap.entrySet()){
            AbstractCache bean = (AbstractCache) SpringContextUtil.getBean(entry.getValue().getClass());
            bean.initCache();
        }
    }
}
